package com.peng.design.rule;

/**
 * SimpleRulesExecutor
 *
 * @author lupeng
 * Created on 2022-03-22
 */
public class SimpleRulesExecutor implements RulesExecutor<Person> {

    @Override
    public boolean execute(Person person, RuleChain<Person> ruleChain) {
        for (Rule<Person> andRule : ruleChain.getAndRules()) {
            if (!andRule.execute(person)) {
                return false;
            }
        }
        for (Rule<Person> orRule : ruleChain.getOrRules()) {
            if (orRule.execute(person)) {
                return true;
            }
        }
        return true;
    }
}
